package com.xja.service.impl;

import com.xja.connutil.ConnUtil;
import com.xja.dao.impl.ZhsDaolmpl;
import com.xja.entity.Indent;
import com.xja.entity.Room;
import com.xja.entity.User;
import com.xja.entity.pojo.UrByIndent;
import com.xja.service.ZhsService;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class ZhsServicelmpl implements ZhsService {
    ZhsDaolmpl zhsDaolmpl = new ZhsDaolmpl();
    public  boolean addUser(User user) {
        Integer i = null;
        try {
            i=zhsDaolmpl.addUser(user);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }
        if (i==null||i==0){
            return false;
        }
        else return true;
    }
    public List<User> fingAllUser(){
        List<User> Userlist = null;
        try {
            Userlist= zhsDaolmpl.fingAllUser();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }
        return  Userlist;
    }
    public List<Room> findRoom(){
        List<Room> roomList = null;
        try {
            roomList = zhsDaolmpl.findRoom();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }return roomList;
    }
    public Integer findUserid(String name) {
        Integer i= null;
        try {
            i = zhsDaolmpl.findUserid(name);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }return i ;
    }
    public boolean indent(Indent indent){
        Integer i = null;
        try {
            i=zhsDaolmpl.indent(indent);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        } if (i==null||i==0){
            return false;
        }
        else return true;
    }
    public List<Indent> selecIndent(Integer userid) {
        List<Indent> indentList= null;
        try {
            indentList = zhsDaolmpl.selecIndent(userid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }
    return indentList;
    }
    public  Integer updateroomstatus(Integer roomid) {
        Integer i = null;
        Connection conn = null;
        try {
            i=zhsDaolmpl.updateroomstatus(roomid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }finally {
            ConnUtil.closeConn();
        }return i;
    }
    public Integer selecRoomId(Integer userid) {
        Integer i = null;
        try {
            i=zhsDaolmpl.selecRoomId(userid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
    }return i;
    }
    public  Integer updateroomstatus1(Integer roomid){
        Integer i = null;
        Connection conn = null;
        try {
            i = zhsDaolmpl.updateroomstatus1(roomid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }finally {
            ConnUtil.closeConn();
        }return i;
    }
    public boolean deleteIndent(Integer userid){
        Integer i = null;
        try {
            i =zhsDaolmpl.deleteIndent(userid);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }if (i==null||i==0){
            return false;
        }
        else return true;
    }
    public List<UrByIndent> selecIndentByName(String username){
        List<UrByIndent> indentList= null;
        try {
            indentList = zhsDaolmpl.selecIndentByName(username);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            ConnUtil.closeConn();
        }
        return indentList;
    }
}


